public class Thread1 implements Runnable {
    private int ticket = 100;

    @Override
    public void run() {
        while (true) {
            synchronized (this) {
                if (ticket > 0) {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName() + "票号为" + ticket);
                    ticket--;
                }


            }
        }

    }
}
    class test {
        public static void main(String[] args) {
            Thread1 t1 = new Thread1();
            Thread h1 = new Thread(t1);
            Thread h2 = new Thread(t1);
            Thread h3 = new Thread(t1);
            h1.setName("窗口1");
            h2.setName("窗口2");
            h3.setName("窗口3");
            h1.start();
            h2.start();
            h3.start();
        }
    }
